﻿Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Roman")
            ListBox1.Items.Add("Arial Black")
            ListBox1.Items.Add("Garamond")
            ListBox1.Items.Add("Somona")

            ListBox2.Items.Clear()
            ListBox2.Items.Add("Times")
            ListBox2.Items.Add("Helvetica")
            ListBox2.Items.Add("Arial")
        End If
    End Sub



    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        While Not ListBox2.Items.Count = 0
            ListBox1.Items.Add(ListBox2.Items(ListBox2.Items.Count - 1))
            ListBox2.Items.Remove(ListBox2.Items(ListBox2.Items.Count - 1).Text)
        End While

    End Sub


    Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click

        While Not ListBox1.Items.Count = 0
            ListBox2.Items.Add(ListBox1.Items(ListBox1.Items.Count - 1))
            ListBox1.Items.Remove(ListBox1.Items(ListBox1.Items.Count - 1).Text)
        End While

    End Sub



    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        For Each selitems As Integer In ListBox2.GetSelectedIndices()
            ListBox1.Items.Add(ListBox2.Items(selitems))
            ListBox2.Items.Remove(ListBox2.Items(selitems).Text)
        Next

        ListBox1.ClearSelection()
        ListBox2.ClearSelection()

    End Sub



    Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click

        For Each selitems As Integer In ListBox1.GetSelectedIndices()
            ListBox2.Items.Add(ListBox1.Items(selitems))
            ListBox1.Items.Remove(ListBox1.Items(selitems).Text)
        Next

        ListBox1.ClearSelection()
        ListBox2.ClearSelection()

    End Sub
End Class